package com.example.test_vue_server.controller;

import com.example.test_vue_server.pojo.User;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class TestController {

//    http://localhost:8080/test1
    @RequestMapping("/test1")
    public Object test1()
    {
        Map r = new HashMap();
        r.put("code",0);
        r.put("msg","成功");
        r.put("data",100);
        return r;
    }

    @GetMapping("/test2")
    public Object test2(String username,String password)
    {
        Map r = new HashMap();
        if("admin".equals(username)&&"123456".equals(password))
        {
            r.put("code",0);
            r.put("msg","成功");
            r.put("data","登陆成功");
        }
        else
        {
            r.put("code",0);
            r.put("msg","失败");
            r.put("data","登陆失败");
        }
        return r;
    }

//    username=admin&password=123456
    @PostMapping("/test3")
    public Object test3(String username,String password)
    {
        System.out.println("用户名密码:"+username+","+password);

        Map r = new HashMap();
        if("admin".equals(username)&&"123456".equals(password))
        {
            r.put("code",0);
            r.put("msg","成功");
            r.put("data","登陆成功");
        }
        else
        {
            r.put("code",0);
            r.put("msg","失败");
            r.put("data","登陆失败");
        }
        return r;
    }


    // @RequestBody json
    // {
    //   username:"admin",
    //   password:"123456"
    // }

    @PostMapping("/test4")
    public Object test4(@RequestBody User user)
    {
        System.out.println(user.getUsername()+user.getPassword());

        Map r = new HashMap();
        if("admin".equals(user.getUsername())&&"123456".equals(user.getPassword()))
        {
            r.put("code",0);
            r.put("msg","成功");
            r.put("data","登陆成功");
        }
        else
        {
            r.put("code",0);
            r.put("msg","失败");
            r.put("data","登陆失败");
        }
        return r;
    }


    @PostMapping("/test7")
    public Object test7(@RequestBody User user)
    {
        Map r = new HashMap();

        r.put("code",0);
        r.put("msg","注册成功");
        r.put("data",user);
        return r;
    }


    @PostMapping("/test8")
    public Object test8(@RequestBody User user)
    {
        Map r = new HashMap();

        // 生成一个token ???
        // username password  加密

        r.put("code",0);
        r.put("msg","注册成功");
        r.put("data",user);
        return r;
    }
}
}
